package com.zzsz.cf.translation.controller;

import com.zzsz.cf.translation.service.ProductCategoryService;
import com.zzsz.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cf/translation/category")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService categoryService;

    // 前端调用此接口获取分类列表（含扩展信息）
    @GetMapping("/list-with-ext")
    public List<Map<String, Object>> getCategoryListWithExt() {
        return categoryService.getCategoryListWithExt();
    }
    // 新增分类（新增）
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Map<String, Object> categoryData) {
        categoryService.addCategory(categoryData);
        return AjaxResult.success();
    }

    // 更新分类状态（启用/禁用）
    @PutMapping("/status")
    public AjaxResult updateStatus(@RequestParam Integer categoryId, @RequestParam Integer status) {
        categoryService.updateCategoryStatus(categoryId, status);
        return AjaxResult.success("状态更新成功");
    }

    @PutMapping("/update")
    public AjaxResult update(@RequestBody Map<String, Object> categoryData) {
        categoryService.updateCategory(categoryData);
        return AjaxResult.success("分类更新成功");
    }

    @DeleteMapping("/{categoryId}")
    public AjaxResult delete(@PathVariable Integer categoryId) {
        categoryService.deleteCategory(categoryId);
        return AjaxResult.success("分类删除成功");
    }

    // 新增：导出分类数据
    @GetMapping("/export")
    public void exportCategories(HttpServletResponse response) {
        categoryService.exportCategories(response);
    }

    // 新增：导入分类数据
    @PostMapping("/import")
    public AjaxResult importCategories(@RequestParam("file") MultipartFile file) {
        int count = categoryService.importCategories(file);
        return AjaxResult.success("导入成功，共导入 " + count + " 条分类数据");
    }
    // 添加统计数据接口
    @GetMapping("/statistics")
    public Map<String, Object> getCategoryStatistics() {
        return categoryService.getCategoryStatistics();
    }

}

